module.exports = {
    chainWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            // #region 忽略生成环境打包的文件
            var externals = {
                'vue': 'Vue',
                'axios': 'axios',
                'element-ui': 'ELEMENT',
                'vue-router': 'VueRouter',
                'vuex': 'Vuex',
                'echarts': 'echarts'
            }
            config.externals(externals)
            // 在html文件中引入相关CDN
            const cdn = {
                css: [ 
                    // element-ui css
                    'https://cdn.bootcss.com/element-ui/2.13.0/theme-chalk/index.css'
                ],
                js: [
                    // vue
                    'https://cdn.staticfile.org/vue/2.5.22/vue.min.js',
                    // vue-router
                    'https://cdn.staticfile.org/vue-router/3.0.2/vue-router.min.js',
                    // vuex
                    'https://cdn.staticfile.org/vuex/3.1.0/vuex.min.js',
                    // axios
                    'https://cdn.staticfile.org/axios/0.19.0-beta.1/axios.min.js',
                    // element-ui js
                    'https://cdn.bootcss.com/element-ui/2.13.0/index.js',
                    //echarts
                    'https://cdn.bootcss.com/echarts/4.6.0/echarts-en.common.js'
                ]
            }
            config.plugin('html')
                .tap(args => {
                    args[0].cdn = cdn
                    return args
                })
        }


    },

    //环境
    publicPath: process.env.NODE_ENV === 'production'
        ? './' : '/',   

    //跨域
    devServer: {
        disableHostCheck: true,//内网穿透
        proxy: {
            '/api': {
                //target: 'http://125.94.170.208:18080',
                //target: 'http://172.23.157.190:8080',
                //target: 'http://119.125.104.99:44444',
                target: 'http://kansuv.info:18080',
                //target: 'http://kansuv.info:13780',

                ws: true,
                changeOrigin: true,
                pathRewrite: {
                    '^/api': ''  //通过pathRewrite重写地址，将前缀/api转为/
                }
            }
        }
    },

    //关闭ellint代码语法检验
    lintOnSave: false

}